WOLF core
WOLF: A Modular Estimation Framework for Robotics
XXXXXXXXXXXXXXXXXXXXXXXXvoid(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
loader.h
Go to the documentation of this file.
1// WOLF - Copyright (C) 2020-2026
2// Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
3// Authors: Joan Solà Ortega (jsola@iri.upc.edu) and
4// Joan Vallvé Navarro (jvallve@iri.upc.edu)
5// All rights reserved.
6//
7// This file is part of WOLF: http://www.iri.upc.edu/wolf
8// WOLF is free software: you can redistribute it and/or modify
9// it under the terms of the GNU General Public License version 3
10// as published by the Free Software Foundation.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19#pragma once
20
21#include <dlfcn.h>
22#include <string>
23#include <map>
24#include <memory>
25#include "yaml-cpp/yaml.h"
26
27namespace wolf
28{
31class Loader
32{
33 protected:
34 int flags_;
35 std::map<std::string, void*> name_resources_;
36
37 public:
40 Loader(int flags = RTLD_LAZY);
41
44 ~Loader();
45
48 void load(std::string _libname_with_so);
49
52 void loadPlugin(std::string _plugin);
53
56 void close(std::string _libname_with_so);
57
60 void closePlugin(std::string _plugin);
61
64 void* isLoaded(std::string _libname_with_so) const;
65
68 void* isLoadedPlugin(std::string _plugin) const;
69
72 void searchAndLoadPlugins(const YAML::Node& _node);
73
76 static std::set<std::string> searchPlugins(const YAML::Node& _node, std::list<YAML::Node>& _visited_nodes);
77
81 static std::set<std::string> searchFieldsRecursive(const YAML::Node& _node,
82 std::list<YAML::Node>& _visited_nodes,
83 const std::string& field);
84
87 size_t size() const;
88};
89typedef std::shared_ptr<Loader> LoaderPtr;
90
91} // namespace wolf
Loader of shared libraries (e.g. wolf plugins) with dlopen.
Definition: loader.h:32
size_t size() const
Returns the number of loaded libraries.
Definition: loader.cpp:116
void loadPlugin(std::string _plugin)
Loads the library of a wolf plugin ('libwolf<plugin>')
Definition: loader.cpp:63
void load(std::string _libname_with_so)
Loads a library (if not loaded)
Definition: loader.cpp:46
void searchAndLoadPlugins(const YAML::Node &_node)
Loads the plugins of all the 'plugin' fields of a YAML node.
Definition: loader.cpp:121
void close(std::string _libname_with_so)
Closes a loaded library.
Definition: loader.cpp:68
void closePlugin(std::string _plugin)
Closes the library of a wolf plugin.
Definition: loader.cpp:89
std::map< std::string, void * > name_resources_
Loaded libraries: dlopen handles indexed by library name.
Definition: loader.h:35
static std::set< std::string > searchFieldsRecursive(const YAML::Node &_node, std::list< YAML::Node > &_visited_nodes, const std::string &field)
Returns the values of all the fields with a given name of a YAML node, recursively (skipping visited ...
Definition: loader.cpp:133
void * isLoaded(std::string _libname_with_so) const
Returns the handle of a library if it is loaded (nullptr otherwise)
Definition: loader.cpp:94
void * isLoadedPlugin(std::string _plugin) const
Returns the handle of the library of a wolf plugin if it is loaded (nullptr otherwise)
Definition: loader.cpp:111
int flags_
dlopen flags
Definition: loader.h:34
~Loader()
Destructor, closing all the loaded libraries.
Definition: loader.cpp:38
Loader(int flags=RTLD_LAZY)
Constructor from the dlopen flags, loading the core plugin.
Definition: loader.cpp:31
static std::set< std::string > searchPlugins(const YAML::Node &_node, std::list< YAML::Node > &_visited_nodes)
Returns the values of all the 'plugin' fields of a YAML node.
Definition: loader.cpp:128
Definition: capture_base.h:23
std::shared_ptr< Loader > LoaderPtr
Definition: loader.h:89